class Student < ActiveRecord::Base
  belongs_to :address
  belongs_to :school
  has_many :attendances
  has_many :communications
  has_many :schedules
  
  def self.get_all
    @student = find(:all, :include => ['address', 'school'], :conditions => ['active = ?', true])
    
    rescue ActiveRecord::RecordNotFound
    nil
  end
  
  def self.get_by_id(id)
    @student = find(id, :include => ['address', 'school'], :conditions => ['active = ?', true])
    
    rescue ActiveRecord::RecordNotFound
    nil
  end
  
  
  def self.deactivate(id)
    conn = connection()
    conn.update("UPDATE students SET active = false WHERE id = #{id}")
  end
  
  def self.activate(id)
    conn = connection()
    conn.update("UPDATE students SET active = true WHERE id = #{id}")
  end
  
end
